package spil;

import desktop_resources.GUI;

public class Chance extends Field {
	public Chance(int fieldNumber) {
		super(fieldNumber);
	}
	
	public void landOnField(Player p) {
		int number = (int)(Math.random() * 7);
		drawCard(p, number);
	}
	
	public void drawCard(Player p, int number) {
		GUI.removeCar(p.getPosition(), p.getName());
		switch(number) {
		case 0: GUI.getUserButtonPressed("G� til Start og f� 200kr", "ok");
		p.getAccount().insert(200);
		p.moveToField(1);
		break;
		case 1: GUI.getUserButtonPressed("G� til Gammel Kongevej\nf� 200kr hvis du passerer start", "ok");
		if(p.getPosition() > 15)
			p.getAccount().insert(200);
		p.moveToField(15);
		break;
		case 2: GUI.getUserButtonPressed("G� til Kgs. Nytorv\nf� 200kr hvis du passerer start", "ok");
		if(p.getPosition() > 28)
			p.getAccount().insert(200);
		p.moveToField(28);
		break;
		case 3: GUI.getUserButtonPressed("G� til R�dhuspladsen", "ok");
		p.moveToField(40);
		break;
		case 4: GUI.getUserButtonPressed("G� i f�ngsel", "ok");
		Jail.jail(p);
		break;
		case 5: GUI.getUserButtonPressed("Gratis ud af f�ngsel", "ok");
		p.getOutOfJailFree();
		break;
		case 6: GUI.getUserButtonPressed("Zakat, betal 50 til hver spiller", "ok");
		for(int i = 0; i < Game.players.length; i++)
			if(!Game.players[i].hasLost()) {
				if(p.getBalance() >= 50) {
					p.getAccount().withdraw(50);
					Game.players[i].getAccount().insert(50);
				} else {
					Game.players[i].getAccount().insert(p.getBalance());
					p.getAccount().withdraw(p.getBalance());
				}
			}
		break;
		}
		GUI.setCar(fieldNumber, p.getName());
	}
}
